﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using UrlsAndRoutes.Infrastructure;

namespace UrlsAndRoutes
{
    public class RouteConfig
    {
        //public static void RegisterRoutes(RouteCollection routes)
        //{
        //    //By default, the routing system checks to see if a URL matches a disk file before evaluating the
        //    //application’s routes
        //    routes.RouteExistingFiles = false;

        //    routes.IgnoreRoute("Content/{filename}.html");

        //    //Alternative for custom RouteHandler
        //    //Route myRoute = new Route("{controller}/{action}", new MvcRouteHandler());
        //    //routes.Add("MyRoute", myRoute);


        //    /*
        //     * pruebas 1
        //     */
        //    //routes.MapRoute("ShopSchema2", "Shop/OldAction", new { controller = "Home", action = "Index" });
        //    //routes.MapRoute("ShopSchema", "Shop/{action}", new { controller = "Home" });
        //    //routes.MapRoute("", "X{controller}/{action}");
        //    //routes.MapRoute("MyRoute", "{controller}/{action}", new { controller = "Home", action = "Index" });
        //    //routes.MapRoute("", "Public/{controller}/{action}",new { controller = "Home", action = "Index" });


        //    /*
        //     * pruebas 2
        //     */
        //    //routes.MapRoute("MyRoute", "{controller}/{action}/{id}", new
        //    //{
        //    //    controller = "Home",
        //    //    action = "Index",
        //    //    id = "DefaultId" //UrlParameter.Optional
        //    //});


        //    /*
        //     * pruebas 3
        //     */
        //    //* captura todo lo que siga en la url y lo guarda en catchall
        //    //routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}", new
        //    //{
        //    //    controller = "Home",
        //    //    action = "Index",
        //    //    id = UrlParameter.Optional
        //    //}, new[] { "URLsAndRoutes.AdditionalControllers" }); //busca primer aca y si no puede resolverlo pasa al resto

        //    //Route myRoute = routes.MapRoute("AddContollerRoute", "{controller}/{action}/{id}/{*catchall}", new
        //    //{
        //    //    controller = "Home",
        //    //    action = "Index",
        //    //    id = UrlParameter.Optional
        //    //}, new[] { "URLsAndRoutes.AdditionalControllers" });
        //    //myRoute.DataTokens["UseNamespaceFallback"] = false; //para que solo busque en el namespace especificado


        //    /*
        //     * pruebas 4
        //     */
        //    routes.MapRoute("MyRoute", "{controller}/{action}/{id}/{*catchall}",
        //        new { controller = "Home", action = "Index", id = UrlParameter.Optional },
        //       new
        //       {
        //           controller = "^H.*", //regEx q pide controllers q empiecen con H
        //           action = "^Index$|^About$",    //actions que sean literalmente Index o About
        //           httpMethod = new HttpMethodConstraint("GET"), //solo pedidos con el metodo GET (el nombre "httpMethod" es anecdotico, lo que importa es q sea un objeto HttpMethodConstraint
        //           customConstraint = new UserAgentConstraint("Chrome"), //ejecuta la constraint UserAgentConstraint para ver si esta ruta machea
        //       },
        //        new[] { "URLsAndRoutes.Controllers" });
        //}

        public static void RegisterRoutes(RouteCollection routes)
        {

            routes.MapRoute("NewRoute", "App/Do{action}", new { controller = "Home" });


            routes.MapRoute("MyRoute", "{controller}/{action}/{id}",
            new
            {
                controller = "Home",
                action = "Index",
                id = UrlParameter.Optional
            }, new[] { "UrlsAndRoutes.Controllers" });//to give priority to main app (not the area)
        }
    }
}